﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace idleQuest2010
{
    public partial class idleForm : Form
    {
        Thread gameThread;        //handles all "game" mechanics
        Thread guiThread;         //handles updating of most GUI objects
        Quest iQuest;
        guiControl guiUpdater;
        Avatar pc;              //holds character attributes
        Inventory inv;         //items

        public idleForm()
        {
            InitializeComponent(); 
        }

        private void idleForm_Load(object sender, EventArgs e)
        {
            startQuest();
        }

        private void startQuest()       //begin a new "game"
        {
            pc = new Avatar();
            inv = new Inventory(pc);
            iQuest = new Quest(this.rtb_main);
            iQuest.loadQuest();
            guiUpdater = new guiControl(iQuest.getPlayer(), iQuest.getInventory(), this.txt_hp, this.txt_mp, this.txt_att, this.txt_def, this.txt_mag, this.txt_level, this.txt_exp, this.txt_gold, this.lbl_invCount, this.txt_weapon, this.txt_offhand, this.txt_torso, this.txt_head, this.txt_feet, this.txt_hands, this.txt_finger, this.txt_back, this.txt_neck, this.lst_inv);  //give the gui updater access to all controls it is responsible for
            gameThread = new Thread(new ThreadStart(iQuest.go));
            gameThread.Name = "GAME_THREAD";
            guiThread = new Thread(new ThreadStart(guiUpdater.startUpdate));
            guiThread.Name = "GUI_THREAD";
            gameThread.Start();         //start "game"
            guiThread.Start();          //start refreshing GUI
        }

        private void idleForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            iQuest.saveQuest();
            Environment.Exit(0);
        }

    }
}






